using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VETFWT3
    {
        public DataRow Convert2ETFWT3(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryETFWT3(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["EWESTKNR"] = " ".PadRight(12 ); 
         dwReturn["EWEPOS"] = " ".PadRight(3 ); 
         dwReturn["EWEPARTANZ"] = " ".PadRight(2 ); 
         dwReturn["EWEPARTNR"] = " ".PadRight(2 ); 
         dwReturn["EWEART"] = " ".PadRight(10 ); 
         dwReturn["EWEARTBEZ"] = " ".PadRight(12 ); 
         dwReturn["EWEDESS"] = " ".PadRight(4 ); 
         dwReturn["EWEFPART"] = " ".PadRight(11 ); 
         dwReturn["EWEFARBE"] = " ".PadRight(10 ); 
         dwReturn["EWEBESCHICH"] = " ".PadRight(5 ); 
         dwReturn["EWEAUSART"] = " ".PadRight(2 ); 
         dwReturn["EWEOPTART"] = " ".PadRight(1 ); 
         dwReturn["EWEWART"] = " ".PadRight(1 ); 
         dwReturn["EWEIBRT"] = " ".PadRight(3 ); 
         dwReturn["EWEISTKLG"] = " ".PadRight(5 ); 
         dwReturn["EWESBRT1"] = " ".PadRight(3 ); 
         dwReturn["EWESBRT2"] = " ".PadRight(3 ); 
         dwReturn["EWESLGMIN"] = " ".PadRight(5 ); 
         dwReturn["EWESLGMAX"] = " ".PadRight(5 ); 
         dwReturn["EWEOPTMAX"] = " ".PadRight(5 ); 
         dwReturn["EWEABSMAX"] = " ".PadRight(5 ); 
         dwReturn["EWEFOLGESA"] = " ".PadRight(1 ); 
         dwReturn["EWEVERW"] = " ".PadRight(1 ); 
         dwReturn["EWEFARBBEZ"] = " ".PadRight(10 ); 
         dwReturn["EWEFILLER1"] = " ".PadRight(18 ); 
         dwReturn["EWEAUFKRS"] = " ".PadRight(2 ); 
         dwReturn["EWEAUFLFD"] = " ".PadRight(6 ); 
         dwReturn["EWEAUFPOS"] = " ".PadRight(3 ); 
         dwReturn["EWESSTKLG1"] = " ".PadRight(5 ); 
         dwReturn["EWESANZ1"] = " ".PadRight(2 ); 
         dwReturn["EWESTOL1"] = " ".PadRight(2 ); 
         dwReturn["EWESLGMIN1"] = " ".PadRight(5 ); 
         dwReturn["EWESLGMAX1"] = " ".PadRight(5 ); 
         dwReturn["EWESWART1"] = " ".PadRight(1 ); 
         dwReturn["EWEFILLER2"] = " ".PadRight(10 ); 
         dwReturn["EWESSTKLG2"] = " ".PadRight(5 ); 
         dwReturn["EWESANZ2"] = " ".PadRight(2 ); 
         dwReturn["EWESTOL2"] = " ".PadRight(2 ); 
         dwReturn["EWESLGMIN2"] = " ".PadRight(5 ); 
         dwReturn["EWESLGMAX2"] = " ".PadRight(5 ); 
         dwReturn["EWESWART2"] = " ".PadRight(1 ); 
         dwReturn["EWEFILLER3"] = " ".PadRight(10 ); 
         dwReturn["EWEAUFTRPOS"] = " ".PadRight(3 ); 
         dwReturn["EWEAUFLG"] = " ".PadRight(5 ); 
         dwReturn["EWELFDPOS"] = " ".PadRight(3 ); 
         dwReturn["EWESNLG"] = " ".PadRight(5 ); 
         dwReturn["EWESSTKLGV"] = " ".PadRight(5 ); 
         dwReturn["EWESSTKLGB"] = " ".PadRight(5 ); 
         dwReturn["EWEWOBST"] = " ".PadRight(1 ); 
         dwReturn["EWEAPOS"] = " ".PadRight(4 ); 
         dwReturn["EWEFILLER4"] = " ".PadRight(3 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapETFWT3(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveETFWT3(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryETFWT3(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapETFWT3(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertETFWT3(dwLocal, ITXDBVERSION);
            }
            UpdateETFWT3(dwLocal);
        }
        public void InsertETFWT3(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO ETFWT3(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryETFWT3(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM ETFWT3 WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM ETFWT3  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "ETFWT3";
            Return = Result;
            return Return;
        }
        public void DeleteETFWT3(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM ETFWT3   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateETFWT3(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE ETFWT3 SET "
                    +"EWESTKNR= :EWESTKNR,"
                    +"EWEPOS= :EWEPOS,"
                    +"EWEPARTANZ= :EWEPARTANZ,"
                    +"EWEPARTNR= :EWEPARTNR,"
                    +"EWEART= :EWEART,"
                    +"EWEARTBEZ= :EWEARTBEZ,"
                    +"EWEDESS= :EWEDESS,"
                    +"EWEFPART= :EWEFPART,"
                    +"EWEFARBE= :EWEFARBE,"
                    +"EWEBESCHICH= :EWEBESCHICH,"
                    +"EWEAUSART= :EWEAUSART,"
                    +"EWEOPTART= :EWEOPTART,"
                    +"EWEWART= :EWEWART,"
                    +"EWEIBRT= :EWEIBRT,"
                    +"EWEISTKLG= :EWEISTKLG,"
                    +"EWESBRT1= :EWESBRT1,"
                    +"EWESBRT2= :EWESBRT2,"
                    +"EWESLGMIN= :EWESLGMIN,"
                    +"EWESLGMAX= :EWESLGMAX,"
                    +"EWEOPTMAX= :EWEOPTMAX,"
                    +"EWEABSMAX= :EWEABSMAX,"
                    +"EWEFOLGESA= :EWEFOLGESA,"
                    +"EWEVERW= :EWEVERW,"
                    +"EWEFARBBEZ= :EWEFARBBEZ,"
                    +"EWEFILLER1= :EWEFILLER1,"
                    +"EWEAUFKRS= :EWEAUFKRS,"
                    +"EWEAUFLFD= :EWEAUFLFD,"
                    +"EWEAUFPOS= :EWEAUFPOS,"
                    +"EWESSTKLG1= :EWESSTKLG1,"
                    +"EWESANZ1= :EWESANZ1,"
                    +"EWESTOL1= :EWESTOL1,"
                    +"EWESLGMIN1= :EWESLGMIN1,"
                    +"EWESLGMAX1= :EWESLGMAX1,"
                    +"EWESWART1= :EWESWART1,"
                    +"EWEFILLER2= :EWEFILLER2,"
                    +"EWESSTKLG2= :EWESSTKLG2,"
                    +"EWESANZ2= :EWESANZ2,"
                    +"EWESTOL2= :EWESTOL2,"
                    +"EWESLGMIN2= :EWESLGMIN2,"
                    +"EWESLGMAX2= :EWESLGMAX2,"
                    +"EWESWART2= :EWESWART2,"
                    +"EWEFILLER3= :EWEFILLER3,"
                    +"EWEAUFTRPOS= :EWEAUFTRPOS,"
                    +"EWEAUFLG= :EWEAUFLG,"
                    +"EWELFDPOS= :EWELFDPOS,"
                    +"EWESNLG= :EWESNLG,"
                    +"EWESSTKLGV= :EWESSTKLGV,"
                    +"EWESSTKLGB= :EWESSTKLGB,"
                    +"EWEWOBST= :EWEWOBST,"
                    +"EWEAPOS= :EWEAPOS,"
                    +"EWEFILLER4= :EWEFILLER4,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("EWESTKNR", OracleType.NVarChar).Value = dwData["EWESTKNR"].ToString(); 
          or1.Parameters.Add("EWEPOS", OracleType.NVarChar).Value = dwData["EWEPOS"].ToString(); 
          or1.Parameters.Add("EWEPARTANZ", OracleType.NVarChar).Value = dwData["EWEPARTANZ"].ToString(); 
          or1.Parameters.Add("EWEPARTNR", OracleType.NVarChar).Value = dwData["EWEPARTNR"].ToString(); 
          or1.Parameters.Add("EWEART", OracleType.NVarChar).Value = dwData["EWEART"].ToString(); 
          or1.Parameters.Add("EWEARTBEZ", OracleType.NVarChar).Value = dwData["EWEARTBEZ"].ToString(); 
          or1.Parameters.Add("EWEDESS", OracleType.NVarChar).Value = dwData["EWEDESS"].ToString(); 
          or1.Parameters.Add("EWEFPART", OracleType.NVarChar).Value = dwData["EWEFPART"].ToString(); 
          or1.Parameters.Add("EWEFARBE", OracleType.NVarChar).Value = dwData["EWEFARBE"].ToString(); 
          or1.Parameters.Add("EWEBESCHICH", OracleType.NVarChar).Value = dwData["EWEBESCHICH"].ToString(); 
          or1.Parameters.Add("EWEAUSART", OracleType.NVarChar).Value = dwData["EWEAUSART"].ToString(); 
          or1.Parameters.Add("EWEOPTART", OracleType.NVarChar).Value = dwData["EWEOPTART"].ToString(); 
          or1.Parameters.Add("EWEWART", OracleType.NVarChar).Value = dwData["EWEWART"].ToString(); 
          or1.Parameters.Add("EWEIBRT", OracleType.NVarChar).Value = dwData["EWEIBRT"].ToString(); 
          or1.Parameters.Add("EWEISTKLG", OracleType.NVarChar).Value = dwData["EWEISTKLG"].ToString(); 
          or1.Parameters.Add("EWESBRT1", OracleType.NVarChar).Value = dwData["EWESBRT1"].ToString(); 
          or1.Parameters.Add("EWESBRT2", OracleType.NVarChar).Value = dwData["EWESBRT2"].ToString(); 
          or1.Parameters.Add("EWESLGMIN", OracleType.NVarChar).Value = dwData["EWESLGMIN"].ToString(); 
          or1.Parameters.Add("EWESLGMAX", OracleType.NVarChar).Value = dwData["EWESLGMAX"].ToString(); 
          or1.Parameters.Add("EWEOPTMAX", OracleType.NVarChar).Value = dwData["EWEOPTMAX"].ToString(); 
          or1.Parameters.Add("EWEABSMAX", OracleType.NVarChar).Value = dwData["EWEABSMAX"].ToString(); 
          or1.Parameters.Add("EWEFOLGESA", OracleType.NVarChar).Value = dwData["EWEFOLGESA"].ToString(); 
          or1.Parameters.Add("EWEVERW", OracleType.NVarChar).Value = dwData["EWEVERW"].ToString(); 
          or1.Parameters.Add("EWEFARBBEZ", OracleType.NVarChar).Value = dwData["EWEFARBBEZ"].ToString(); 
          or1.Parameters.Add("EWEFILLER1", OracleType.NVarChar).Value = dwData["EWEFILLER1"].ToString(); 
          or1.Parameters.Add("EWEAUFKRS", OracleType.NVarChar).Value = dwData["EWEAUFKRS"].ToString(); 
          or1.Parameters.Add("EWEAUFLFD", OracleType.NVarChar).Value = dwData["EWEAUFLFD"].ToString(); 
          or1.Parameters.Add("EWEAUFPOS", OracleType.NVarChar).Value = dwData["EWEAUFPOS"].ToString(); 
          or1.Parameters.Add("EWESSTKLG1", OracleType.NVarChar).Value = dwData["EWESSTKLG1"].ToString(); 
          or1.Parameters.Add("EWESANZ1", OracleType.NVarChar).Value = dwData["EWESANZ1"].ToString(); 
          or1.Parameters.Add("EWESTOL1", OracleType.NVarChar).Value = dwData["EWESTOL1"].ToString(); 
          or1.Parameters.Add("EWESLGMIN1", OracleType.NVarChar).Value = dwData["EWESLGMIN1"].ToString(); 
          or1.Parameters.Add("EWESLGMAX1", OracleType.NVarChar).Value = dwData["EWESLGMAX1"].ToString(); 
          or1.Parameters.Add("EWESWART1", OracleType.NVarChar).Value = dwData["EWESWART1"].ToString(); 
          or1.Parameters.Add("EWEFILLER2", OracleType.NVarChar).Value = dwData["EWEFILLER2"].ToString(); 
          or1.Parameters.Add("EWESSTKLG2", OracleType.NVarChar).Value = dwData["EWESSTKLG2"].ToString(); 
          or1.Parameters.Add("EWESANZ2", OracleType.NVarChar).Value = dwData["EWESANZ2"].ToString(); 
          or1.Parameters.Add("EWESTOL2", OracleType.NVarChar).Value = dwData["EWESTOL2"].ToString(); 
          or1.Parameters.Add("EWESLGMIN2", OracleType.NVarChar).Value = dwData["EWESLGMIN2"].ToString(); 
          or1.Parameters.Add("EWESLGMAX2", OracleType.NVarChar).Value = dwData["EWESLGMAX2"].ToString(); 
          or1.Parameters.Add("EWESWART2", OracleType.NVarChar).Value = dwData["EWESWART2"].ToString(); 
          or1.Parameters.Add("EWEFILLER3", OracleType.NVarChar).Value = dwData["EWEFILLER3"].ToString(); 
          or1.Parameters.Add("EWEAUFTRPOS", OracleType.NVarChar).Value = dwData["EWEAUFTRPOS"].ToString(); 
          or1.Parameters.Add("EWEAUFLG", OracleType.NVarChar).Value = dwData["EWEAUFLG"].ToString(); 
          or1.Parameters.Add("EWELFDPOS", OracleType.NVarChar).Value = dwData["EWELFDPOS"].ToString(); 
          or1.Parameters.Add("EWESNLG", OracleType.NVarChar).Value = dwData["EWESNLG"].ToString(); 
          or1.Parameters.Add("EWESSTKLGV", OracleType.NVarChar).Value = dwData["EWESSTKLGV"].ToString(); 
          or1.Parameters.Add("EWESSTKLGB", OracleType.NVarChar).Value = dwData["EWESSTKLGB"].ToString(); 
          or1.Parameters.Add("EWEWOBST", OracleType.NVarChar).Value = dwData["EWEWOBST"].ToString(); 
          or1.Parameters.Add("EWEAPOS", OracleType.NVarChar).Value = dwData["EWEAPOS"].ToString(); 
          or1.Parameters.Add("EWEFILLER4", OracleType.NVarChar).Value = dwData["EWEFILLER4"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
